package com.yanqu.road.dataHelper.action.excel;

import com.yanqu.road.dataHelper.gameServer.GameServer;
import com.yanqu.road.dataHelper.manager.DataMgr;
import com.yanqu.road.dataHelper.repair.BaseRepair;
import com.yanqu.road.entity.player.UserInfo;

import java.math.BigInteger;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author xx
 * @Date 2020/11/11
 */
public class TriggerRmbMall extends BaseRepair {

    public TriggerRmbMall(GameServer gameServer) {
        super(gameServer);
    }

    @Override
    public void repair(long param1, String param2) {

    }
    //触发礼包一条龙三个日志
    public void go1(){
        List<Map<String, String>> listMap = new ArrayList<>();
        listMap = getLog1();
        DataMgr.addData(listMap);
    }
    public void go2(){
        List<Map<String, String>> listMap = new ArrayList<>();
        listMap = getLog2();
        DataMgr.addData(listMap);
    }
    public void go3(){
        List<Map<String, String>> listMap = new ArrayList<>();
        listMap = getLog3();
        DataMgr.addData(listMap);
    }

    private List<Map<String, String>> getLog1() {
        List<Map<String, String>> dataList = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * " +
                " from t_l_trigger_rmbmall_buy " +
                " where `time` > ? AND `time` < ?";
        try {
            call = getGameServer().getLogConnection().prepareCall(sql);
            int i=1;
            call.setString(i++,"2020-11-01");
            call.setString(i++,"2020-11-04");
            rs = call.executeQuery();
            while (rs.next()) {
                Map<String,String> temp = new ConcurrentHashMap<>();
                temp.put("serverId",String.valueOf(getGameServer().getServerInfo().getServerId()));
                temp.put("userId",checkNullToEmpty(rs.getString("userId")));
                temp.put("activityId",checkNullToEmpty(rs.getString("activityId")));
                temp.put("conditionId",checkNullToEmpty(rs.getString("conditionId")));
                temp.put("mallId",checkNullToEmpty(rs.getString("mallId")));
                temp.put("price",checkNullToEmpty(rs.getString("price")));
                temp.put("time",checkNullToEmpty(rs.getString("time")));
                dataList.add(temp);
            }
        } catch (SQLException ex) {
            getGameServer().getLogger().error("异常错误", ex);
        } finally {
            getGameServer().closeConnection(call, rs);
        }
        return dataList;
    }
    private List<Map<String, String>> getLog2() {
        List<Map<String, String>> dataList = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * " +
                " from t_l_trigger_rmbmall_precharge " +
                " where `time` > ? AND `time` < ?";
        try {
            call = getGameServer().getLogConnection().prepareCall(sql);
            int i=1;
            call.setString(i++,"2020-11-01");
            call.setString(i++,"2020-11-04");
            rs = call.executeQuery();
            while (rs.next()) {
                Map<String,String> temp = new ConcurrentHashMap<>();
                temp.put("serverId",String.valueOf(getGameServer().getServerInfo().getServerId()));
                temp.put("userId",checkNullToEmpty(rs.getString("userId")));
                temp.put("activityId",checkNullToEmpty(rs.getString("activityId")));
                temp.put("orderNo",checkNullToEmpty(rs.getString("orderNo")));
                temp.put("mallId",checkNullToEmpty(rs.getString("mallId")));
                temp.put("price",checkNullToEmpty(rs.getString("price")));
                temp.put("time",checkNullToEmpty(rs.getString("time")));
                dataList.add(temp);
            }
        } catch (SQLException ex) {
            getGameServer().getLogger().error("异常错误", ex);
        } finally {
            getGameServer().closeConnection(call, rs);
        }
        return dataList;
    }
    private List<Map<String, String>> getLog3() {
        List<Map<String, String>> dataList = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select *,FROM_UNIXTIME(triggerTime,'%Y年%m月%d %H:%i:%s') as triggerTime2 " +
                " from t_l_trigger_rmbmall_trigger " +
                " where `time` > ? AND `time` < ?";
        try {
            call = getGameServer().getLogConnection().prepareCall(sql);
            int i=1;
            call.setString(i++,"2020-11-01");
            call.setString(i++,"2020-11-04");
            rs = call.executeQuery();
            while (rs.next()) {
                Map<String,String> temp = new ConcurrentHashMap<>();
                temp.put("serverId",String.valueOf(getGameServer().getServerInfo().getServerId()));
                temp.put("userId",checkNullToEmpty(rs.getString("userId")));
                temp.put("activityId",checkNullToEmpty(rs.getString("activityId")));
                temp.put("conditionId",checkNullToEmpty(rs.getString("conditionId")));
                temp.put("titleId",checkNullToEmpty(rs.getString("titleId")));
                temp.put("mallId",checkNullToEmpty(rs.getString("mallId")));
                temp.put("triggerPrice",checkNullToEmpty(rs.getString("triggerPrice")));
                temp.put("triggerTime",checkNullToEmpty(rs.getString("triggerTime2")));
                temp.put("time",checkNullToEmpty(rs.getString("time")));
                dataList.add(temp);
            }
        } catch (SQLException ex) {
            getGameServer().getLogger().error("异常错误", ex);
        } finally {
            getGameServer().closeConnection(call, rs);
        }
        return dataList;
    }
}
